package com.xjy.headfirst.迭代器.复杂迭代器;

import java.util.Iterator;

/**
 * decription:
 *
 * @author 辛纪元
 * @since 2022-07-18
 */

public class Waitress {

    MenuComponent menuComponent;

    public Waitress(MenuComponent menuComponent) {
        this.menuComponent = menuComponent;
    }

    public void printMenu(){
        menuComponent.print();
    }

    public void printVegetarianMenu(){
        Iterator<MenuComponent> iterator = menuComponent.createIterator();
        while (iterator.hasNext()) {
            MenuComponent next = iterator.next();
            try {
                if (next.isVegetarian()) {
                    next.print();
                }
            }catch (UnsupportedOperationException unsupportedOperationException){
            }

        }
    }

}
